package com.trace.app.controller;

import com.trace.app.entity.Product;
import com.trace.app.entity.ResponseResult;
import com.trace.app.service.ProductService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;

/**
 * (Product)表控制层
 *
 * @author lionkliu
 * @since 2024-03-17 15:55:10
 */
@RestController
@RequestMapping("product")
public class ProductController {

    @Resource
    private ProductService productService;

    @GetMapping("/list")
    public ResponseResult listProduct() {
        return productService.listProduct();
    }

    @GetMapping("/page")
    public ResponseResult selectPage(@RequestParam("pageNum") Integer pageNum,
                                     @RequestParam("pageSize") Integer pageSize) {
        return productService.selectPage(pageNum,pageSize);
    }

    @GetMapping("{id}")
    public ResponseResult selectOne(@PathVariable Integer id) {
        return productService.selectOne(id);
    }

    @PostMapping
    public ResponseResult insert(@RequestBody Product product) {
        return productService.insertOne(product);
    }

    @PutMapping
    public ResponseResult update(@RequestBody Product product) {
        return productService.updateOne(product);
    }

    @DeleteMapping("/{id}")
    public ResponseResult delete(@PathVariable Integer id) {
        return productService.deleteById(id);
    }

}
